package com.liuyz;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;


@SuppressWarnings({"all"})
public class HashMap_ {

    public static void main(String[] args) {
        class Cat {
            private String name;
            private int age;

            public Cat(String name, int age) {
                this.name = name;
                this.age = age;
            }

            @Override
            public String toString() {
                return "Cat{" +
                        "name='" + name + '\'' +
                        ", age=" + age +
                        '}';
            }
        }

        Map map = new HashMap();
        map.put("node1", "张三");
        map.put("node2", "张三");
        map.put("node2", "张三2");
        Cat cat = new Cat("小黄", 3);
        map.put("node3", cat);
        cat.name = "小黄2";
        map.put("node4", cat);
        map.put(null, null);
        map.put(null, "abc");
        map.put(new Cat("小黑", 4), "饿了");
        System.out.println(map);

        System.out.println("===========遍历");
        System.out.println("-----------keySet");
        Set keySet = map.keySet();
        for (Object key : keySet) {
            System.out.println(key + "-" + map.get(key));
        }

        System.out.println("-----------values");
        Collection values = map.values();
        for (Object value : values) {
            System.out.println(value);
        }

        System.out.println("-----------entrySet");
        Set entrySet = map.entrySet();
        for (Object o : entrySet) {
            Map.Entry entry = (Map.Entry) o;
            System.out.println(entry.getKey() + "-" + entry.getValue());
        }

        ConcurrentHashMap concurrentHashMap = new ConcurrentHashMap();
        concurrentHashMap.entrySet();
        concurrentHashMap.keySet();
        concurrentHashMap.values();
        concurrentHashMap.put("key", "value");
    }

}
